{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "AXROaNNEtx0g"
      },
      "outputs": [],
      "source": [
        "!pip install scapy matplotlib"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "wT2owBsLt5ek"
      },
      "outputs": [],
      "source": [
        "from scapy.all import IP, ICMP, sr, traceroute\n",
        "\n",
        "# Define the target host\n",
        "target_host = [\"bing.com\", \"google.com\", \"duckduckgo.com\"]\n",
        "\n",
        "# Perform the traceroute\n",
        "result, _ = traceroute(target_host, maxttl=5)\n",
        "\n",
        "# Display the results\n",
        "result.show()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "RX8taOgugq_M"
      },
      "outputs": [],
      "source": [
        "from scapy.all import sniff\n",
        "\n",
        "# Lists to store packet sizes and timestamps\n",
        "packet_sizes = []\n",
        "timestamps = []\n",
        "\n",
        "#Handle packets and get the necessary data\n",
        "def packet_handler(packet):\n",
        "  print(packet)\n",
        "  packet_sizes.append(len(packet))\n",
        "  timestamps.append(packet.time)\n",
        "\n",
        "# Start packet sniffing on the default network interface\n",
        "sniff(prn=packet_handler, count=100)"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import matplotlib.pyplot as plt\n",
        "\n",
        "# Create a plot\n",
        "plt.figure(figsize=(16, 8))\n",
        "plt.plot(timestamps, packet_sizes, marker='o')\n",
        "plt.xlabel(\"Time\")\n",
        "plt.ylabel(\"Packet Size\")\n",
        "plt.title(\"Packet Size over Time\")\n",
        "plt.grid(True)\n",
        "plt.show()"
      ],
      "metadata": {
        "id": "WEUyMfhFUJxQ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from scapy.all import sniff\n",
        "from scapy.layers.inet import IP\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "# Lists to store packet sizes and timestamps\n",
        "packet_sizes = []\n",
        "timestamps = []\n",
        "\n",
        "def packet_handler(packet):\n",
        "  print(packet)\n",
        "  packet_sizes.append(len(packet))\n",
        "  timestamps.append(packet.time)\n",
        "\n",
        "# Start packet sniffing on the default network interface\n",
        "sniff(prn=packet_handler, filter=\"ip\", count=100)\n",
        "\n",
        "# Create a plot\n",
        "plt.figure(figsize=(16, 8))\n",
        "plt.plot(timestamps, packet_sizes, marker='o')\n",
        "plt.xlabel(\"Time\")\n",
        "plt.ylabel(\"Packet Size\")\n",
        "plt.title(\"Packet Size over Time\")\n",
        "plt.grid(True)\n",
        "plt.show()\n"
      ],
      "metadata": {
        "id": "kQIJfuJE2Wjd"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install netifaces"
      ],
      "metadata": {
        "id": "fj9QwdCZXewJ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import netifaces\n",
        "\n",
        "def generate_routing_table():\n",
        "    routing_table = []\n",
        "    for interface in netifaces.interfaces():\n",
        "        addresses = netifaces.ifaddresses(interface)\n",
        "        if netifaces.AF_INET in addresses:\n",
        "            for entry in addresses[netifaces.AF_INET]:\n",
        "                if 'netmask' in entry and 'addr' in entry:\n",
        "                    routing_entry = {\n",
        "                        'interface': interface,\n",
        "                        'destination': entry['addr'],\n",
        "                        'netmask': entry['netmask']\n",
        "                    }\n",
        "                    routing_table.append(routing_entry)\n",
        "    return routing_table\n",
        "\n",
        "routing_table = generate_routing_table()\n",
        "for entry in routing_table:\n",
        "        print(f\"Interface: {entry['interface']}\")\n",
        "        print(f\"Destination: {entry['destination']}\")\n",
        "        print(f\"Netmask: {entry['netmask']}\")\n",
        "        print(\"-\" * 30)\n"
      ],
      "metadata": {
        "id": "hir370m3XjVE"
      },
      "execution_count": null,
      "outputs": []
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}